package com.robot.ui;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

public class LoginFrame extends BaseFrame {
	private static final long serialVersionUID = -7193462568008136217L;
	// 窗口的用户QQ的输出框
	private JLabel rcodeImgLable;
	public LoginFrame(){
		this.setSize(320, 260);
		this.setLocationRelativeTo(null);// 在窗口中间显示窗口
		this.setContentPane(createContentPane());// 设置窗口中的panel
		this.setUndecorated(true); // 是否要边框
		// this.setAlwaysOnTop(true); //置顶显示
		ImageIcon backImage = null;
		JLabel backLabel = null;
		try {
			backImage = new ImageIcon(ImageIO.read(getClass()
					.getResourceAsStream("images/login.jpg")));
			backLabel = new JLabel(backImage);
		} catch (IOException e) {

		}
		backLabel.setBounds(0, 0, backImage.getIconWidth(),
				backImage.getIconHeight());
		((JPanel) this.getContentPane()).setOpaque(false);// 如果此组件应该是不透明的，则为
															// true
		this.getLayeredPane().add(backLabel, new Integer(Integer.MIN_VALUE));
	}

	// 初始化窗口的方法
	public void showView(BufferedImage verify) {
		rcodeImgLable.setIcon(new ImageIcon(verify));
		this.setVisible(true);
	}

	// 创建主panel并初始化
	public JPanel createContentPane() {
		JPanel panel = new JPanel(new BorderLayout());
		JLabel lable = null;
		try {
			lable = new JLabel(new ImageIcon(ImageIO.read(getClass()
					.getResourceAsStream("images/name.gif"))));
		} catch (IOException e) {

		}
		panel.add(lable, BorderLayout.NORTH);
		panel.add(createRcodeImgPane(), BorderLayout.CENTER);
		panel.add(createBtnPane(), BorderLayout.SOUTH);
		panel.setBorder(new EmptyBorder(0, 80, 0, 80));
		// 上 左 下 右
		return panel;
	}

	
	private Component createRcodeImgPane() {
		JPanel panel = new JPanel(new BorderLayout()); 
		rcodeImgLable = new JLabel("");
		panel.add(rcodeImgLable);
		return panel;
	}

	// 创建放按钮的panel
	public JPanel createBtnPane() {
		JPanel panel = new JPanel(new GridLayout(1, 1, 0, 0));
		panel.setOpaque(false);
		panel.setBorder(new EmptyBorder(1,50,0, 50));
		
		JButton cancel = new JButton("退出");
		cancel.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				System.exit(0);
			}
		});
		panel.add(cancel);
		return panel;
	}

	
	public JLabel getRcodeImgLable() {
		return rcodeImgLable;
	}

	public void setRcodeImgLable(JLabel rcodeImgLable) {
		this.rcodeImgLable = rcodeImgLable;
	}
}
